package net.wanho.controller;

import lombok.RequiredArgsConstructor;
import net.wanho.dto.LoginUserDTO;
import net.wanho.service.LoginService;
import net.wanho.util.CurrentUtil;
import net.wanho.vo.LoginUserVo;
import net.wanho.vo.R;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Component
@RequiredArgsConstructor
@RestController
public class LoginController {
    private final LoginService loginService;

    @GetMapping("/captchaImage")
    public R captchaImage() {
        Map<String,String> map = loginService.captchaImage();
        return R.success(map);
    }
    @PostMapping("/login")
    public R login(@RequestBody LoginUserDTO loginUserDTO) {

        String token = loginService.login(loginUserDTO);
        return R.success("登录成功",token);
    }

    @GetMapping("/curr-user")
    public R currUser() {
        LoginUserVo loginUserVo = loginService.getCurrentUser();
        return R.success(loginUserVo);
    }
    @DeleteMapping("/logout")
    public R logout() {
        CurrentUtil.removeUserId();
        return R.success();
    }




}
